Ext.namespace("Task.Close");

Task.Close.panel = function() {
	Task.FeedBack.win.instance = new Task.FeedBack.win();
	
	this.txtTaskTitle = new Ext.form.TextField({
		fieldLabel:'任务名称',
		width: 150
	});
	this.dtStart = new Ext.form.DateField({
		fieldLabel:'制定开始时间',
		width: 100,
		format: 'Y-m-d'
	});
	this.dtEnd = new Ext.form.DateField({
		fieldLabel:'制定结束时间',
		width: 100,
		format: 'Y-m-d'
	});
//	this.dtFulfill = new Ext.form.DateField({
//		fieldLabel:'开始时间',
//		width: 100,
//		format: 'Y-m-d'
//	});
    
	this.queryBtn = new Ext.Button({
		iconCls: 'icon-search',
        text: '查找',
        handler: this.queryTask,
        scope: this
	});
//	this.queryPanel = new Ext.form.FormPanel({
//		title:'查询条件',
//		height:100,
//		id:'queryForm',
//		labelWidth: 80,
//		labelAlgin:'right',
//        collapsible: true,
//		region: 'north',
//		frame:true,
//		items:[
//				{layout:'column',items:[
//		        {columnWidth:0.3,layout:'form',items:[this.txtTaskTitle]},
//		        {columnWidth:0.3,layout:'form',items:[this.dtStart]},
//		         {columnWidth:0.3,layout:'form',items:[this.dtEnd]}
//				]}
//		 ],
//		 buttonAlign:'center',
//		 buttons:[this.queryBtn]
//		
//	});
	
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../task/searchTaskExe.form?timesnap=' + Date.parse(new Date())
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			fields: ['TASK_ID', 'TASK_TITLE', 'TASK_DATE','USER_NAME','TASK_COMPLETE_DATE','TASK_EXE_STATUS', 'TASK_DISPATCHER','TASK_CONTENT','TASK_STATUS','TASK_ORIGIN','TASK_NOTE','TASK_EXECUTOR','DIS_NAME',
			'TASK_EXE_ID','TASK_EXE_PERCENT','TASK_EXE_STATE','HAS_ACCESSORY','TASK_EXE_UPDATE_DATE']
		}),listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	        	 status : [3,4],
       	             taskTitle:this.txtTaskTitle.getValue(),
			  		 dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
			   		 dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):''
       	          });    
              },
              scope:this 
	    	}
		}
	});
	this.renderDays = function(value){
		var date = Date.parseDate(value.substring(0,10),"Y-m-d");
		var days = parseInt((date.getTime()-new Date().getTime())/(1000*60*60*24));
		if(days<0)
			return "<font color='red'>是</font>";
		else
			return "<font size=1>否</font>";
	};
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	};
	this.renderOrigin = function(value){
		return OMS.TASKORIGIN[value];
	}
	var getFeedbackMessageconn = new Ext.data.Connection({
		url:'../task/getLastFeedBackMessage.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	this.colModel = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
			{header: 'TASK_ID', width: 50, hidden: true, dataIndex: 'TASK_ID'},
			{header: '附件', width: 30, dataIndex: 'HAS_ACCESSORY',renderer:this.renderAccessory},
			{header: '任务名称',align:'left', width: 200, dataIndex: 'TASK_TITLE'},
			{header: '派发时间', dataIndex: 'TASK_DATE'},
			{header: '完成时间', dataIndex: 'TASK_EXE_UPDATE_DATE'},
			{header: '派发人', dataIndex: 'DIS_NAME'},
			{header: '是否逾期', dataIndex: 'TASK_COMPLETE_DATE',renderer:this.renderDays},
			{header: '任务状态', dataIndex: 'TASK_EXE_STATUS',renderer:this.renderTaskStatus},
			{header: '任务来源', dataIndex: 'TASK_ORIGIN',renderer:this.renderOrigin}
	    ]
	});
	
	this.gridPanel = new Ext.grid.GridPanel({
		region: 'center',
		cm:this.colModel,
		stripeRows: true, 
		store:this.store,
		tbar: ['任务名称:',this.txtTaskTitle,'定制开始时间:', this.dtStart, '定制结束时间:', this.dtEnd, this.queryBtn],
		sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        viewConfig: { forceFit: true },
        listeners:{
      		  rowdblclick : function( grid, rowIndex,e){
        		   var data = grid.store.getAt(rowIndex).data;
        		  
        			Utils.request(getFeedbackMessageconn,{
        				params:{
        					taskId:data.TASK_EXE_ID
        				},
        				success:function(resp){
        					data.TASK_EXE_STATE =resp.result;
        	        		Task.FeedBack.win.instance.initDetail(data);
        					Task.FeedBack.win.instance.show();
        				}
        			});	   

			}
       }
	})
	Task.Close.panel.superclass.constructor.call(this, {
		title:'已办任务',
		layout:'border',
		items:[this.gridPanel],
		listeners:{
			render:this.queryTask
		}
	});
};
Ext.extend(Task.Close.panel, Ext.Panel, {
	queryTask :function(){
		this.store.load({
			params:{
				start : 0,
				limit : 15,
				status:[3,4],
				taskTitle:this.txtTaskTitle.getValue(),
			    dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
			    dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):''
				}
		});
	},
    renderAccessory : function(value) {
		if (value != null && value == '0') {
			return "@";
		} else {
			return "";
		}
	}
});


